package com.lee.dhsg.service.impl;

import com.lee.dhsg.dao.CatalogDao;
import com.lee.dhsg.domain.Catalog;
import com.lee.dhsg.service.CatalogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

@Service
public class CatalogServiceImpl implements CatalogService {

    @Autowired
    CatalogDao catalogDao;

    @Override
    public List<Catalog> selectFcatalogByCourseid(Integer courseid) {
        return catalogDao.selectFcatalogByCourseid(courseid);
    }

    @Override
    public List<Catalog> selectCatalogByFcatalogid(Integer fcatalogid) {
        return catalogDao.selectCatalogByFcatalogid(fcatalogid);
    }

    @Override
    public Map<Catalog, List<Catalog>> selectAllCatalogByCourseid(Integer courseid) {

        Map<Catalog, List<Catalog>> catalogListMap = new LinkedHashMap<>();
        List<Catalog> catalogList = new ArrayList<>();

        List<Catalog> fcatalogList = catalogDao.selectFcatalogByCourseid(courseid);

        for (Catalog catalog : fcatalogList) {
            catalogList = catalogDao.selectCatalogByFcatalogid(catalog.getCatalogid());
            catalogListMap.put(catalog, catalogList);
        }

        return catalogListMap;
    }
}
